#include "threadPool.hpp"
#include <iostream>
#include "Task.hpp"
#include <ctime>
#include <cstdlib>
#include <unistd.h>
#include "log.hpp"

int main()
{
    // logMessage(NORMAL, "%s %d %c %f \n", "这是一条日志信息", 1234, 'c', 3.14);


    srand((unsigned long)time(nullptr) ^ getpid());
    ThreadPool<Task> *tp = new ThreadPool<Task>();
    tp->run();

    while (true)
    {
        // 生产的过程，制作任务的时候是要花时间的
        int x = rand()%100 + 1;
        usleep(4583);
        int y = rand()%30 + 1;
        Task t(x, y, [](int x, int y)->int{
            return x + y;
        });

        //std::cout << "制作任务完成 : " << x << " + " << y << " = ?" << std::endl;
        logMessage(DEBUG, "制作任务完成 : %d + %d = ?", x, y);

        // 推送任务到线程池中
        tp->pushTask(t);

        sleep(1);
    }

    return 0;
}